<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../common/connect.php");
include("../common/common.php");

$opt = trim(CheckUrlParamNoDie("opt"));
$showtype = trim(CheckUrlParamNoDie("showtype"));
$tag = CheckUrlParamNoDie("tag");
$id = CheckUrlParamNoDie("id");

if(isset($_POST["Site_Submit"]))
{
	$okey = trim(GetPostParamStr("Okey"));
	$systag = trim(GetPostParamStr("systag"));
	$xiaotag = trim(GetPostParamStr("xiaotag"));
	$redian = trim(GetPostParamStr("redian"));
	if($redian == "" || $redian == 0)
		$redian = 0;
	$paixu = trim(GetPostParamStr("paixu"));
	if($paixu == "" || $paixu == 0)
		$paixu = 0;
	$dianjishu = trim(GetPostParamStr("dianjishu"));
	if($dianjishu == "" || $dianjishu == 0)
		$dianjishu = rand(400,235159);
	
	if($id == "")
	{
		$sql = "insert into gwt_top (skey,dtype,xtype,num,hot,ranges) values ('$okey', '$systag','$xiaotag', $dianjishu, $redian, $paixu)";
		mysql_query($sql);
		echo "<script>window.history.go(-2);</script>";
	}
	else
	{
		$sql2 = "update gwt_top set skey='$okey', dtype='$systag', xtype='$xiaotag', num=$dianjishu, hot=$redian, ranges=$paixu where id=$id";
		mysql_query($sql2);
		if (mysql_affected_rows() == 1)
			echo "<script>window.history.go(-2);</script>";
	}
}

if ($opt == "del" && $id != "")
{
	mysql_query("delete from gwt_top where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>风云榜关键字管理</title>
<style type="text/css">
body { font-size:12px;}
table,tr,th,td { margin:0; padding:0; color:#666;}
table { background:#09F;}
th { background:#BEF;}
th,td { padding:10px;}
tr { background:#fff;}
a { color:#00F;}
ul,ol,li { list-style:none;}
/***网站提交***/
.Unbound { background:#f2eeef; width:500px; padding:10px; position:absolute; top:10px; left:240px; font-size:12px;}
.Unbound .unss { background:#FFF; padding:10px; border:1px solid #999;}
.Unbound .sel { height:30px; border-bottom:1px solid #ddd;}
.Unbound .sel .Close a { float:right; text-indent:0; width:40px; display:inline-block;}
.Unbound .ted { overflow:hidden;}
.Unbound .ted .ted_tj { margin-top:10px;}
.Unbound .ted .ted_tj span { width:90px; text-align:right; display:block; float:left;}
.Unbound .ted .ted_tj .tedinp,.Unbound .ted .ted_tj textarea { height:22px; line-height:22px; border:1px solid #ddd; font-size:12px; padding:0 5px; color:#666; overflow:hidden;}
.Unbound .ted .ted_tj select.tedinp { padding:0;}
.Unbound .ted .ted_tj textarea { width:360px; height:70px; }
.Unbound .ted .sz_btn { margin:20px auto; width:133px; overflow:hidden;}
.Unbound .ted .sz_btn input { background:url(http://www.gouwutu.com/new/doc/img/sebtn.jpg) no-repeat; cursor:pointer; padding:0; color:#FFF; font-weight:bold; width:133px; height:45px; border:0;}
#recomtag ul { padding:0;}
</style>
<script language="javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
<!--
var where = new Array(11); 
function comefrom(loca,locaxiaotag)
{
	this.loca = loca; this.locaxiaotag = locaxiaotag; 
} 
where[0] = new comefrom("请选择大类","请选择小类");
where[1] = new comefrom("热门搜索","|最热搜索|当季热款|流行元素|配饰元素|家居风格|衣服风格");
where[2] = new comefrom("服装","|女装|男装|鞋子|内衣/家居服|箱包|配饰|珠宝|其它"); 
where[3] = new comefrom("数码","|手机|电脑|办公数码|配件|影音"); 
where[4] = new comefrom("美容","|护肤|彩妆|美体|品牌|功效|国产品牌"); 
where[5] = new comefrom("母婴","|宝宝服饰|宝宝食品|宝宝用品|宝宝玩具|孕妇服饰|孕妇食用"); 
where[6] = new comefrom("食品","|零食|民生食品|冲饮品|保健|茶叶"); 
where[7] = new comefrom("文体","|户外|运动|图书|度假旅游|收藏|乐器"); 
where[8] = new comefrom("家居","|日用/礼品|布艺|厨房/餐饮|日化/清洁|成人用品|工艺饰品|布艺软饰|五金|家具"); 
where[9] = new comefrom("车/玩具/宠物","|趣味玩具|游戏|汽车配件|骑行|宠物|鲜花植物"); 
where[10] = new comefrom("商城","|淘宝商城|京东商城|当当|麦包包|1号店网上超市|凡客" ); 
where[11] = new comefrom("团购","|美团|赶集团|聚美优品|嘀嗒团|大众点评团|糯米团");
 
function select()
{
	with(document.creator.systag)
	{
		var loca2 = options[selectedIndex].value;
	}
	for(i = 0;i < where.length;i ++)
	{
		if(where[i].loca == loca2)
		{
			loca3 = (where[i].locaxiaotag).split("|");
			for(j = 0;j < loca3.length;j++)
			{
				with(document.creator.xiaotag)
				{
					length = loca3.length; options[j].text = loca3[j]; options[j].value = loca3[j];
					var loca4=options[selectedIndex].value;
				}
			}
			break;
		}
	}
	document.creator.newlocation.value=loca2+loca4;
}
function init()
{
	with(document.creator.systag)
	{
		length = where.length;
		for(k=0;k<where.length;k++)
		{
			options[k].text = where[k].loca;
			options[k].value = where[k].loca;
		}
		options[selectedIndex].text = where[0].loca;
		options[selectedIndex].value = where[0].loca;
	}
	with(document.creator.xiaotag)
	{
		loca3 = (where[0].locaxiaotag).split("|");
		length = loca3.length;
		for(l=0;l<length;l++)
		{
			options[l].text = loca3[l];
			options[l].value = loca3[l];
		}
		options[selectedIndex].text = loca3[0];
		options[selectedIndex].value = loca3[0];
	}
}
-->
</script>
</head>
<body onload="init()">
<div style="padding:10px;"><a href="http://www.gouwutu.com/top/index.php" target="_blank">点击打开购物兔风云榜</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit"><font color="#FF0000">添加关键字</font></a>&nbsp;&nbsp;&nbsp;&nbsp;
    <select  class="tedinp" name="Site_Tag" id="Site_Tag" size="1">
        <option value="1" selected='selected'>序列号</option>
        <option value="2">关键字</option>
    </select>&nbsp;&nbsp;
    <input type="text" size="20" id="showtype" name="showtype" value="" style="width:200px;">&nbsp;&nbsp;
    <input type="button" value="查找" onclick="javascript:OnFind();">&nbsp;&nbsp;<a href="union.php">默认显示</a>
</div>
<table cellpadding="10" cellspacing="1" border="0" width="100%" style="color:red">
	<tr>
    	<th>序号</th>
    	<th>关键字</th>
        <th>大类</th>
        <th>小类</th>
        <th>点击数</th>
        <th>是否热点</th>
        <th>时间</th>
        <th>排列</th>
        <th>操作</th>
    </tr>
    <?php
    $sql = "";
	if($showtype != "" && $tag == '1')
		$sql .= " where id=$showtype";
	if($showtype != "" && $tag == '2')
		$sql .= " where skey='$showtype'";
		
	$sql = "select * from gwt_top".$sql." order by id desc limit 30";	
	$result = mysql_query($sql);
	$i = 0;
	while( $result && $row = mysql_fetch_assoc($result))
	{
	?>
    <tr align="center">
    	<td><?php echo $row["id"]; ?></td>
    	<td><?php echo $row["skey"]; ?></td>
        <td><?php echo $row["dtype"]; ?></td>
        <td><?php echo $row["xtype"]; ?></td>
        <td><?php echo $row["num"]; ?></td>
        <td><?php echo $row["hot"]; ?></td>
        <td><?php echo $row["time"]; ?></td>
        <td><?php echo $row["ranges"]; ?></td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit&id=<?php echo $row["id"]; ?>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:if(confirm('确实要删除吗?'))location='?opt=del&id=<?php echo $row["id"]; ?>'">删除</a>
    </tr>
    <?php } ?>
</table>
<?php 
if($opt == "edit")
{ 	
	//$siid = "";
	$okey = "";
	$systag = "";
	$xiaotag = "";
	$redian = "";
	$paixu = "";
	$dianjishu = "";
	
	if( $id != "" )
	{
		$esql = "select * from gwt_top where id=$id limit 1";
		$eresult = mysql_query( $esql );
		if( $eresult && $row2 = mysql_fetch_assoc( $eresult ) )
		{
			//$siid = 
			$okey = $row2["skey"];
			$systag = $row2["dtype"];
			$xiaotag = $row2["xtype"];
			$redian = $row2["num"];
			$paixu = $row2["hot"];
			$dianjishu = $row2["ranges"];
		}
	}
?>
<div style="display:block;" class="Unbound">
    <div class="unss">
        <div class="sel"><h2><span class="Close"><a href="union.php">关闭</a></span>编辑/添加</h2></div>
        <div class="ted">
            <form onsubmit="return sunbmintSS()" method="post" action="union.php?id=<?php echo $id; ?>" name="creator">
                <div class="ted_tj"><span>关键字：</span><input type="text" value="<?php echo $okey; ?>" name="Okey" id="Okey" maxlength="100" style="width:260px;" class="tedinp"></div>
                <div class="ted_tj"><span>大类：</span><select size="1"  id="systag" name="systag" class="tedinp" onChange = "select()"></select></div>
                <div class="ted_tj"><span>小类：</span><select size="1"  id="xiaotag" name="xiaotag" class="tedinp" onChange = "select()"></select></div>
 
                <div class="ted_tj"><span>点击数：</span><input type="text" value="<?php echo $dianjishu; ?>" name="dianjishu" id="dianjishu" maxlength="100" style="width:60px;" class="tedinp"><font color="#FF0000";>&nbsp;&nbsp;点击数如果为空，系统自动随机，否则以输入数为主</font></div>
                <div class="ted_tj"><span>是否热点：</span><input type="text" value="<?php echo $redian; ?>" name="redian" id="redian" maxlength="100" style="width:30px;" class="tedinp"><font color="#FF0000">&nbsp;&nbsp;默认为“0”；输入"1"该关键字为热点</font></div>
                <div class="ted_tj"><span>排序：</span><input type="text" value="<?php echo $paixu; ?>" name="paixu" id="paixu" maxlength="100" style="width:30px;" class="tedinp"><font color="#FF0000">&nbsp;&nbsp;如果输入1~10，风云榜该小类里面的关键字根据输入数排序</font></div>
                <p class="sz_btn"><input type="submit" value="提 交" name="Site_Submit" id="Site_Submit"></p>
                <span><!-----奇怪的360 去掉设置就没有了------></span>
            </form>
        </div>
    </div>
</div>
<?php } ?>
</body>
</html>
<script type="text/javascript">
function OnFind()
{
	var site_tag = document.getElementById("Site_Tag").value;
	var input_tradeid = document.getElementById("showtype").value;
	window.location.href= "union.php?showtype=" + input_tradeid + "&tag=" + site_tag ;
}
function sunbmintSS()
{
	var systag = document.getElementById("systag").value;
	var xiaotag = document.getElementById("xiaotag").value;
	
	if(systag == "请选择大类" || xiaotag == "请选择小类")
	{
		alert("请选择类型");
		return false;
	}
	
	return true;
}
</script>
